package com.qingke.java.tools;

import java.util.Scanner;

public class QingkeConsole {
	private static Scanner scan = new Scanner(System.in);
	
	public static void println(String msg) {
		System.out.println(msg);
	}
	
	public static void println(Object obj) {
		System.out.println(obj);
	}
	
	public static String askUserInputString(String msg) {
		String inputString = null;
		while(true) {
			System.out.print(msg + ">");
			inputString = scan.nextLine();
			
			if(inputString != null && inputString.trim().length() > 0) {
				break;
			}
			
			System.out.println("Please enter non-empty string!");
		}
		return inputString;
	}
	
	public static int askUserInputInt(String msg) {
		int inputInt = -1;
		
		while(true) {
			String str = askUserInputString(msg);
			try {
			inputInt = Integer.valueOf(str);
			break;
			} catch(NumberFormatException e) {
				System.out.println("Please enter a number value!");
			}	
		}
		return inputInt;
	}
	
	public static void exit() {
		System.out.println("Bye-bye");
		System.exit(0);
	}
}
